package com.zzj.mailservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.zzj.mailservice.base.Result;
import com.zzj.mailservice.model.dto.MessageDTO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class MailController {

    @Resource
    private JavaMailSender mailSender;

    @Operation(summary = "发送右键", description = "目标邮箱 标题 内容")
    @PostMapping("sendMessage")
    public Result sendMessage(@RequestBody @Validated MessageDTO in)
    {
        String to = in.getTo();
        String title =in.getTitle();
        String content = in.getContent();
        SimpleMailMessage message=new SimpleMailMessage();
        message.setFrom("wesley@zzjtpp.top");
        message.setTo(to);
        message.setSubject(title);
        message.setText(content);
        mailSender.send(message);
        return Result.success();
    }

    @GetMapping("test")
    public String test(){
        return "test";
    }
}
